import Router from 'koa-router';
import { permissionController } from '../controllers/permission.controller';
import checkPermission from '../middleware/permissionMiddleware';

const router = new Router();

router.get('/permissions', checkPermission('view_permission'), permissionController.query);
router.post('/permissions', checkPermission('create_permission'), permissionController.insert);
router.put('/permissions/:id', checkPermission('update_permission'), permissionController.update);
router.delete('/permissions/:id', checkPermission('delete_permission'), permissionController.remove);
router.get('/permissions/:id', checkPermission('view_permission'), permissionController.queryById);

/**
 * @swagger
 * tags:
 *   name: Permission
 *   description: 权限相关操作
 */

/**
 * @swagger
 * /permissions:
 *   get:
 *     summary: 获取权限列表
 *     tags: [Permission]
 *     parameters:
 *       - $ref: '#/components/parameters/PageParam'
 *       - $ref: '#/components/parameters/SizeParam'
 *       - $ref: '#/components/parameters/UserIdParam'
 *     responses:
 *       200:
 *         description: 成功返回权限列表
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: object
 *                   properties:
 *                     list:
 *                       type: array
 *                       items:
 *                         $ref: '#/components/schemas/PermissionListDto'
 *                     total:
 *                       type: integer
 *                       example: 10
 *       401:
 *         description: 用户未授权访问
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 401
 *                 message:
 *                   type: string
 *                   example: "未授权"
 *       500:
 *         description: 服务器内部错误
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 500
 *                 message:
 *                   type: string
 *                   example: "服务器内部错误"
 */

/**
 * @swagger
 * /permissions:
 *   post:
 *     summary: 创建新权限
 *     tags: [Permission]
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/PermissionCreateDto'
 *     responses:
 *       201:
 *         description: 权限创建成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: boolean
 *                   example: true
 *       401:
 *         description: 用户未授权访问
 *       500:
 *         description: 服务器内部错误
 */

/**
 * @swagger
 * /permissions/{id}:
 *   put:
 *     summary: 更新权限信息
 *     tags: [Permission]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         description: 权限ID
 *         schema:
 *           type: integer
 *     requestBody:
 *       required: true
 *       content:
 *         application/json:
 *           schema:
 *             $ref: '#/components/schemas/PermissionUpdateDto'
 *     responses:
 *       200:
 *         description: 更新成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: boolean
 *                   example: true
 *       404:
 *         description: 权限未找到
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务器内部错误
 */

/**
 * @swagger
 * /permissions/{id}:
 *   delete:
 *     summary: 删除权限
 *     tags: [Permission]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         description: 权限ID
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 删除成功
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: boolean
 *                   example: true
 *       404:
 *         description: 权限未找到
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务器内部错误
 */

/**
 * @swagger
 * /permissions/{id}:
 *   get:
 *     summary: 获取单个权限信息
 *     tags: [Permission]
 *     parameters:
 *       - in: path
 *         name: id
 *         required: true
 *         description: 权限ID
 *         schema:
 *           type: integer
 *     responses:
 *       200:
 *         description: 返回权限信息
 *         content:
 *           application/json:
 *             schema:
 *               type: object
 *               properties:
 *                 code:
 *                   type: integer
 *                   example: 200
 *                 message:
 *                   type: string
 *                   example: "成功"
 *                 data:
 *                   type: object
 *                   $ref: '#/components/schemas/PermissionSingleDto'
 *       404:
 *         description: 权限未找到
 *       401:
 *         description: 未授权
 *       500:
 *         description: 服务器内部错误
 */

export default router;
